package com.vadmin.vadminjava.servlet;

import com.alibaba.fastjson.JSONObject;
import com.vadmin.vadminjava.service.WxCouponBusinessService;
import com.vadmin.vadminjava.service.WxCouponClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/* ***********************************************************
 *
 * 微信的卡劵接口，客户端专用
 *
 * **********************************************************/
@RestController
@RequestMapping ("/WxCouponClientServlet")
public class WxCouponClientServlet {

    @Autowired
    WxCouponClientService wxCouponClientService;
    @Autowired
    WxCouponBusinessService wxCouponBusinessService;



    //发商家券给指定用户，或者说领取
    @RequestMapping(value = {"/fetchBusinessCouponUrl"})
    public String fetchBusinessCouponUrl(@RequestParam Map<String, Object> params) throws Exception {
        JSONObject paramJ = new JSONObject();
        params.keySet().forEach(i -> paramJ.put(i, params.get(i)));

        //paramJ.put("openId", "oqGpx6O8tX3tTAEx0SyzfTVS0d_Q"); //用户对于公众号的openid

        return wxCouponBusinessService.fetchBusinessCouponUrl(paramJ).toJSONString();

    }


    /**
     * 商家券列表
     * @param params
     * @param httpServletRequest
     * @return
     */
    @RequestMapping (value = {"/couponListOfBusiness"})
    public String wxWorkExternalUserList(@RequestParam Map<String, Object> params,HttpServletRequest httpServletRequest) {
        JSONObject paramJ = new JSONObject();
        params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
        return wxCouponClientService.wxCouponBusinessList(paramJ).toString();
    }


    /**
     * 商家券详情
     * @param params
     * @param httpServletRequest
     * @return
     */
    @RequestMapping (value = {"/couponDetailOfBusiness"})
    public String couponDetailOfBusiness(@RequestParam Map<String, Object> params,HttpServletRequest httpServletRequest) {
        JSONObject paramJ = new JSONObject();
        params.keySet().forEach(i -> paramJ.put(i, params.get(i)));
        return wxCouponClientService.couponDetailOfBusiness(paramJ).toString();
    }

}
